/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interface;

import Images.RMImages;
import StaticClass.ArrSocket;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import sun.java2d.ScreenUpdateManager;

/**
 *
 * @author Oho
 */
public class IClient extends javax.swing.JPanel {

    /**
     * Creates new form IClient
     */
    public IClient() {
        initComponents();
                
    }
    RMImages img;
    int chiso;
    private String nameMachine;

    public int getChiso() {
        return chiso;
    }

    public IClient(RMImages img, int so, String name) {
        initComponents();
        this.img = img;
        this.chiso = so;
        this.nameMachine = name;
        txtName.setText(name);
        //   this.txtName.setText(name);// = name;
        //  txtNameMachine.setText(name);
        //      this.txtName.setText(nameMachine);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtName = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(249, 250));
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                formMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                formMouseExited(evt);
            }
        });

        jLabel1.setText("...");
        jLabel1.setToolTipText("");
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel1MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel1MouseExited(evt);
            }
        });

        txtName.setText("..............");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addComponent(txtName))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        // TODO add your handling code here:
        //ArrSocket.icl = this;
        //JOptionPane.showMessageDialog(null, "asdasd");
    }//GEN-LAST:event_formMouseClicked
    int flag = 1;
    Creen sc;
    private void formMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_formMouseEntered

    private void formMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseExited
        // TODO add your handling code here:
    }//GEN-LAST:event_formMouseExited

    private void jLabel1MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseExited
        // TODO add your handling code here:
        sc.dispose();
        flag = 1;
    }//GEN-LAST:event_jLabel1MouseExited

    private void jLabel1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseEntered
        // TODO add your handling code here:
        if (flag == 1) {
            ImageIcon im = img.getIcon();
            Image img2 = im.getImage();
            img2 = img2.getScaledInstance(600, 400, Image.SCALE_SMOOTH);
            im = new ImageIcon(img2);
            JLabel jb = new JLabel(im);
            //jb.setSize(im.getIconWidth(), im.getIconHeight());
            jb.setBounds(0, 0, im.getIconWidth(), im.getIconHeight());
            sc = new Creen(jb);

            Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

            sc.setBounds(evt.getXOnScreen() + 30, 0, im.getIconWidth() - 15, im.getIconHeight() + 10);
            // sc.repaint();
            if (sc.getX() + sc.getWidth() > dim.getWidth()) {
            sc.setBounds(evt.getYOnScreen()-10,evt.getYOnScreen(), im.getIconWidth() + 15, im.getIconHeight() + 10);
                
            }
            sc.setVisible(true);
            flag = 0;
        }
    }//GEN-LAST:event_jLabel1MouseEntered

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
        // TODO add your handling code here:
        ArrSocket.icl = this;
    }//GEN-LAST:event_jLabel1MouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JLabel jLabel1;
    private javax.swing.JLabel txtName;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the nameMachine
     */
    public String getNameMachine() {
        return nameMachine;
    }

    /**
     * @param nameMachine the nameMachine to set
     */
    public void setNameMachine(String nameMachine) {
        this.nameMachine = nameMachine;
    }
}
